<?php


namespace App\factory;


use App\Models\User;
use Illuminate\Http\Request;

class Blance implements PayFactory
{
    /**
     * @param $data
     * @throws \Exception
     * 余额支付
     */
    public static function payType($data)
    {
        // TODO: Implement payType() method.
        //获取当前登录用户余额
        $user_money = User::findMoney($data['uid']);
        //判断余额 与 支出
        $pay_money = $data['order_money'];
        if(  $user_money<0 || $user_money-$pay_money<0){
            throw new \Exception('余额不足');
        }
        //支出后修改余额
        User::UpMoney($data['uid'],$user_money-$pay_money);
        return['200',"余额支付成功",['余额支付'=>$pay_money,'剩余余额'=>$user_money-$pay_money]];
    }
}
